﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GDGeek;

public class WidgetMultiLevelButton : MonoBehaviour
{
    [SerializeField]
    private Transform _backgroundTransform;
    [SerializeField]
    private float _duration;
    public float infalteScale;
    public float defalteScale;

    [SerializeField]
    private expandDirction _dirction;
    private enum expandDirction
    {
        horizontal,
        vertical,
    }

    [SerializeField]
    private Tween.Style style;
    [SerializeField]
    private Easing.Method _method;

    private bool isInflated = false;

    public List<Transform> buttons;

    private void Update() {
        
    }
    public void infalte()
    {
        TweenTask tt = new TweenTask(delegate
        {
            if (_dirction == expandDirction.horizontal)
            {
                Tween tween = TweenValue.Begin(_backgroundTransform.gameObject, _duration, _backgroundTransform.lossyScale.x, infalteScale, delegate (float val)
                {
                    Vector3 scale = _backgroundTransform.lossyScale;
                    scale.x = val;
                    _backgroundTransform.setGlobalScale(scale);
                });
                tween.method = _method;
                return tween;
            }
            else
            {
                Tween tween = TweenValue.Begin(_backgroundTransform.gameObject, _duration, _backgroundTransform.lossyScale.y, infalteScale, delegate (float val)
                 {
                     Vector3 scale = _backgroundTransform.lossyScale;
                     scale.y = val;
                     _backgroundTransform.setGlobalScale(scale);
                 });
                tween.method = _method;
                return tween;
            }
        });

        TaskManager.Run(tt);
    }

    public void defalte()
    {
        TweenTask tt = new TweenTask(delegate
        {
            if (_dirction == expandDirction.horizontal)
            {
                Tween tween = TweenValue.Begin(_backgroundTransform.gameObject, _duration, _backgroundTransform.lossyScale.x, defalteScale, delegate (float val)
                {
                    Vector3 scale = _backgroundTransform.lossyScale;
                    scale.x = val;
                    _backgroundTransform.setGlobalScale(scale);
                });
                tween.method = _method;
                return tween;
            }
            else
            {
                Tween tween = TweenValue.Begin(_backgroundTransform.gameObject, _duration, _backgroundTransform.lossyScale.y, defalteScale, delegate (float val)
                 {
                     Vector3 scale = _backgroundTransform.lossyScale;
                     scale.y = val;
                     _backgroundTransform.setGlobalScale(scale);
                 });
                tween.method = _method;
                return tween;
            }
        });

        TaskManager.Run(tt);
    }
    public void toggleExpand()
    {
        if (!isInflated)
        {
            infalte();
            isInflated = true;
        }else{
            defalte();
            isInflated = false;
        }
    }
}
